
import drawQrcode from "../../utils/weapp.qrcode.esm"

Page({
  data: {
    text: 'Hello 二维码！',
    result: ''
  },
  onLoad(options) {
    this.handleClick()
    /*drawQrcode({
      width: 200,
      height: 200,
      canvasId: 'myQrcode',
      text: this.data.text,
      image: {
        imageResource: '../../images/wbb.jpeg',
        dx: 70,
        dy: 70,
        dWidth: 60,
        dHeight: 60
      }
    })*/
  },
  handleClick() {
    drawQrcode({
      width: 200,
      height: 200,
      canvasId: 'myQrcode',
      text: this.data.text,
      // background: 'red',
      // foreground: '#00f',
      image: {
        imageResource: '../../images/wbb.jpeg',
        dx: 70,
        dy: 70,
        dWidth: 60,
        dHeight: 60
      }
    })
  },
  handleScanCode() {
    const self = this
    wx.scanCode({
      onlyFromCamera: true,
      success (res) {
        console.log(res)
        console.log(res.result)
        self.setData({
          result: res.result
        })
      },
      fail(e) {
        console.log(e)
      }
    })
  },
  handleCopy() {
    // console.log(this.data.result)
    wx.setClipboardData({
      data: this.data.result,
      success (res) {
        // wx.vibrateShort()
        wx.vibrateLong()
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  }
})